﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>ajax读取json格式数据练习</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    <script src="jquery-1.7.2.js" type="text/javascript"></script>
    <script src="school.js" type="text/javascript"></script>
    <!--<script src="CityDemo.js" type="text/javascript"></script>-->
    <script type="text/javascript">
        $(function () {
            $("#btnCity").click(function () {

                //                $.getScript("CityDemo.js");
                //                $("#divArrayCity").empty();
                //                var strCity = "";
                //                $.each(cityData, function (CityInfoindex, CityInfo) {
                //                    strCity += "Citycode:" + CityInfo["code"] + "<br />";
                //                    strCity += "Cityname:" + CityInfo["name"] + "<br />";
                //                    strCity += "<hr/>";
                //                });
                //                $("#divArrayCity").html(strCity);

                $.getScript("school.js");
                $("#divSchool").empty();
                var strSchool = "";
                var TotalProdut = 0;
                var parentTotal = 0;
                //                //一级数据表
                //                for (var i = 0; i < schoolList.length; i++) {
                //                    parentTotal++;
                //                    strSchool += "ID:" + schoolList[i].id + "@";
                //                    strSchool += "NAME:" + schoolList[i].name+ "|";
                //                    strSchool += "<br/>";
                //                }

                //二级数据表
                for (var i = 0; i < schoolList.length; i++) {
                    parentTotal++;
                    var school = schoolList[i].school;
                    for (var j = 0; j < school.length; j++) {
                        strSchool += "ParentID:" + schoolList[i].id + "@";
                        strSchool += "ID:" + school[j].id + "#";
                        strSchool += "NAME:" + school[j].name + "|";
                        strSchool += "<br/>";
                        TotalProdut++;
                    }
                }

                //                //所有数据显示
                //                for (var i = 0; i < schoolList.length; i++) {
                //                    parentTotal++;
                //                    var school = schoolList[i].school;
                //                    for (var j = 0; j < school.length; j++) {
                //                        strSchool += "ParentID: " + schoolList[i].id + "<br/>";
                //                        strSchool += "ParentName: " + schoolList[i].name + "<br/>";
                //                        strSchool += "      " + "ID: " + school[j].id + "<br/>";
                //                        strSchool += "      " + "Name: " + school[j].name + "<br/>";
                //                        strSchool += "<hr />";
                //                        TotalProdut++;
                //                    }
                //                }
                $("#divTotalProduct").html("二级项数:<span style='color:red'>" + TotalProdut + "</span>");
                $("#divParentTotalProduct").html("一级项数:<span style='color:red'>" + parentTotal + "</span>");
                $("#divSchool").html(strSchool);
            })
        })
    </script>
</head>
<body>
    <div id="main">
        <input type="button" name="btnCity" value="获取数据" id="btnCity" />
        <br />
        <div id="divParentTotalProduct">
        </div>
        <div id="divTotalProduct">
        </div>
        <div id="divSchool">
        </div>
    </div>
</body>
</html>
